home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir24 / jnos110g.zip / FINGERD.C < prev    next >
C/C++ Source or Header  |  1994-07-05  |  5KB  |  194 lines

  1. /* Internet Finger server */
  2. #include "global.h"
  3. #ifdef FINGERSERVER
  4. #include "files.h"
  5. #include "mbuf.h"
  6. #include "socket.h"
  7. #include "session.h"
  8. #include "proc.h"
  9. #include "smtp.h"
  10. #include "dirutil.h"
  11. #include "commands.h"
  12. #include "mailbox.h"
  13.  
  14. #ifdef MAILFOR
  15. extern int dombmailfor __ARGS((int argc,char *argv[],void *p));
  16. #endif
  17.  
  18. static void fingerd __ARGS((int s,void *unused,void *p));
  19. #if defined SAMCALLB || QRZCALLB
  20. extern int cb_lookup __ARGS((int, char *, FILE *));
  21. #endif
  22.  
  23.  
  24. /* Start up finger service */
  25. int
  26. finstart(argc,argv,p)
  27. int argc;
  28. char *argv[];
  29. void *p;
  30. {
  31.     int16 port;
  32.  
  33.     if(argc < 2)
  34.         port = IPPORT_FINGER;
  35.     else
  36.         port = atoi(argv[1]);
  37.  
  38.     return start_tcp(port,"FINGER Server",fingerd,1024);
  39. }
  40.  
  41. int
  42. fin0(argc,argv,p)
  43. int argc;
  44. char *argv[];
  45. void *p;
  46. {
  47.     int16 port;
  48.  
  49.     if(argc < 2)
  50.         port = IPPORT_FINGER;
  51.     else
  52.         port = atoi(argv[1]);
  53.  
  54.     return stop_tcp(port);
  55. }
  56.  
  57. #define FLINE 128
  58.  
  59. struct finfo {
  60.     char *name;
  61.     int (*func) __ARGS((int argc,char *argv[],void *p));
  62. };
  63.  
  64. struct finfo Finfo[] = {
  65.     "iheard",   doipheard,
  66. #ifdef MAILBOX
  67.     "mstat",    dombmailstats,
  68. #endif
  69. #ifdef ALLCMD
  70.     "info",     doinfo,
  71. #endif
  72. #ifdef AX25
  73.     "ax25",     doaxstat,
  74. #ifdef MAILFOR
  75.     "mailfor",  dombmailfor,
  76. #endif // MAILFOR
  77. #endif // AX25
  78. #ifdef NETROM
  79.     "netrom",   donrstatus,
  80. #endif
  81.     "memstat",  dostat,
  82.     "socket",   dosock,
  83.     "tcpview",  doview,
  84.     "users",    dombstatus,
  85. #ifdef ASY
  86.     "asystat",  doasystat,
  87. #endif
  88. /* This gives a lot of info you might not want to be known - WG7J */
  89. /*    "ifconfig", doifconfig, */
  90. #ifdef RIP
  91.     "rip", doripstat,
  92. #endif
  93.     NULL,
  94. };
  95.  
  96. static void
  97. fingerd(s,unused,p)
  98. int s;
  99. void *unused;
  100. void *p;
  101. {
  102.     char user[80];
  103.     int ulen,found;
  104.     FILE *fp;
  105.     char *file,*cp;
  106.     struct finfo *fi;
  107.     int outsave;
  108.     char line[FLINE+1];
  109.  
  110.     sockmode(s,SOCK_ASCII);
  111.     sockowner(s,Curproc);
  112.     log(s,"open Finger");
  113.     recvline(s,user,80);
  114.     rip(user);
  115.     ulen = strlen(user);
  116.  
  117. #ifdef CONVERS
  118.     if(ulen && !strcmp(user,"conf"))
  119.         ShowConfUsers(s,0,NULL);
  120.     else if( ulen && !strcmp(user,"links"))
  121.         ShowConfLinks(s,1);
  122.     else {
  123. #endif
  124.         for(fi=Finfo;fi->name;fi++)
  125.             if(!stricmp(fi->name,user))
  126.                 break;
  127.         if(ulen && fi->name) {
  128.             outsave = Curproc->output;
  129.             Curproc->output = s;
  130.             fi->func(1,NULL,NULL);
  131.             Curproc->output = outsave;
  132.         } else {
  133.             if(ulen == 0){
  134.                 fp = dir(Fdir,0);
  135.                 if(fp == NULLFILE)
  136.                     usputs(s,"No finger information available\n");
  137.                 else
  138.                     usputs(s,"Known users on this system:\n");
  139.             } else {
  140. #ifdef USERLOG
  141.                 char *newargv[2];
  142.  
  143.                 outsave = Curproc->output;
  144.                 Curproc->output = s;
  145.                 newargv[1] = user;
  146.                 dombuserinfo(0,newargv,NULL);
  147.                 Curproc->output = outsave;
  148. #endif
  149. #if defined SAMCALLB || QRZCALLB
  150.                 cb_lookup (s, user, (FILE *) 0);
  151. #endif
  152.                 file = pathname(Fdir,user);
  153.                 cp = pathname(Fdir,"");
  154.             /* Check for attempted security violation (e.g., somebody
  155.              * might be trying to finger "../ftpusers"!)
  156.              */
  157.                 if(strncmp(file,cp,strlen(cp)) != 0){
  158.                     fp = NULLFILE;
  159.                     usprintf(s,"Invalid user name %s\n",user);
  160.                 } else if((fp = fopen(file,READ_TEXT)) == NULLFILE) {
  161.                 /* Now search the finger database file for this user - WG7J */
  162.                     found = 0;
  163.                     if((fp = fopen(Fdbase,READ_TEXT)) != NULLFILE) {
  164.                         while(fgets(line,FLINE,fp) != NULLCHAR)
  165.                             if(!strncmp(line,user,ulen)) {
  166.                                 usputs(s,line);
  167.                                 found = 1;
  168.                                 break;
  169.                             }
  170.                         fclose(fp);
  171.                         fp = NULLFILE;
  172.                     }
  173.                     if(!found)
  174.                         usprintf(s,"No user info for %s\n",user);
  175.                 }
  176.                 free(cp);
  177.                 free(file);
  178.             }
  179.             if(fp != NULLFILE){
  180.                 sendfile(fp,s,ASCII_TYPE,0,NULL);
  181.                 fclose(fp);
  182.             }
  183.         }
  184. #ifdef CONVERS
  185.     }
  186. #endif
  187.     if(ulen == 0 && Listusers != NULL)
  188.         (*Listusers)(s);
  189.     close_s(s);
  190.     log(s,"close Finger");
  191. }
  192.  
  193. #endif /* FINGERSERVER */
  194.